<template>
  <div class="mod-sys__log-login">
    <el-form :inline="true" :model="dataForm" @keyup.enter="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.creatorName" :placeholder="$t('logLogin.creatorName')" clearable></el-input>
      </el-form-item>
      <el-form-item placeholder="日志类型" class="role-list">
        <el-select @change="selectChanged" model-value="登录日志">
          <el-option value="0">登录日志</el-option>
          <el-option value="1">操作日志</el-option>
          <el-option value="2">异常日志</el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">{{ $t("query") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="info" @click="exportHandle()">{{ $t("export") }}</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="dataListLoading" :data="dataList" border @sort-change="dataListSortChangeHandle" style="width: 100%">
      <el-table-column prop="creatorName" :label="$t('logLogin.creatorName')" header-align="center" align="center"></el-table-column>
      <el-table-column prop="operation" :label="$t('logLogin.operation')" header-align="center" align="center">
        <template v-slot="scope">
          {{ scope.row.operation === 0 ? $t("logLogin.operation0") : $t("logLogin.operation1") }}
        </template>
      </el-table-column>
      <el-table-column prop="ip" :label="$t('logLogin.ip')" header-align="center" align="center"></el-table-column>
      <el-table-column prop="userAgent" :label="$t('logLogin.userAgent')" header-align="center" align="center" width="150" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="createDate" :label="$t('logLogin.createDate')" sortable="custom" header-align="center" align="center" width="180"></el-table-column>
    </el-table>
    <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total" layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle"> </el-pagination>
  </div>
</template>

<script lang="ts">
import useView from "@/hooks/useView";
import { defineComponent, reactive, toRefs } from "vue";
export default defineComponent({
  setup() {
    const state = reactive({
      getDataListURL: "/sys/log/login/page",
      getDataListIsPage: true,
      exportURL: "/sys/log/login/export",
      dataForm: {
        creatorName: "",
        status: ""
      }
    });
    return { ...useView(state), ...toRefs(state) };
  },
  methods: {
    selectChanged(e) {
      if (e == 0) {
        this.$router.push("/sys/log-login");
      }
      if (e == 1) {
        this.$router.push("/sys/log-operation");
      }
      if (e == 2) {
        this.$router.push("/sys/log-error");
      }
    }
  }
});
</script>
